package com.hotel.controller;

import com.hotel.entity.Orders;
import com.hotel.entity.Room;
import com.hotel.response.MessageUtils;
import com.hotel.response.RestResponse;
import com.hotel.service.OrdersService;
import com.hotel.service.RoomService;
import com.hotel.utils.CommonRedisHelperUtil;
import com.sun.corba.se.impl.logging.POASystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author 夏智力
 * @FileName OccupationController
 * @date 2021/6/25 9:49
 * @Software: IntelliJ IDEA
 */

@RestController
@RequestMapping("/occupation")
public class OccupationController {

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private RoomService roomService;

    @Autowired
    private CommonRedisHelperUtil commonRedisHelperUtil;

    // 根据手机号和入住时间查询订单
    @RequestMapping(path = "/list", method = RequestMethod.GET)
    public RestResponse findOrder(String phone, String startTime) {
        List<Orders> orders = ordersService.selectOrderByPhone(phone, startTime);
        return MessageUtils.success(orders);
    }

    // 根据房间类型查询可选的房间
    @RequestMapping(path = "/room/list", method = RequestMethod.GET)
    public RestResponse findRoom(String typeName) {
        List<Room> rooms = roomService.selectRoomByTypeName(typeName);
        return MessageUtils.success(rooms);
    }

    // 为客人分配房间
    @RequestMapping(path = "/room/choice", method = RequestMethod.POST)
    public void distribution(Room room) {
        // 给房间上锁
        room.setStatus(1);
        roomService.updateRoom(room);
    }

    // 客人退房
    @RequestMapping(path = "/room/checkout", method = RequestMethod.POST)
    public void CheckOutRoom(String roomName) {
        // 解锁房间
        Room room = roomService.selectRoomByRoomName(roomName);
        room.setStatus(0);
        Date date = new Date();

        roomService.updateRoom(room);
        // 判断是提前退房还是正常退房
    }
}
